<html>
	<body>
		<script src="js/jquery.min.js"></script>
		<script src="recorder.js"></script>
		<input onclick="startRecording()" type="button" id="bt" value="start" />
		<script>
			var start=false;
			var recorder;
			var onFail = function(e) {
				console.log('Rejected!', e);
			};
			var onSuccess = function(s) {
				var context = new webkitAudioContext();
				var mediaStreamSource = context.createMediaStreamSource(s);
				recorder = new Recorder(mediaStreamSource);
				recorder.record();
			}
			window.URL = window.URL || window.webkitURL;
			navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
			
			function startRecording() {
				if(start){
					start=false;
					$('#bt').val("start");
					recorder.stop();
					recorder.exportWAV(function(s) {
						var s = window.URL.createObjectURL(s);
						uploadFile(s,"s.wav");
					});
					
				}else{
					start=true;
					$('#bt').val("send");
					if (navigator.getUserMedia) {
						navigator.getUserMedia({audio: true}, onSuccess, onFail);
					} else {
						console.log('navigator.getUserMedia not present');
					}
				}
			}
			
			function uploadFile(blobFile,fileName) {
			    var request = new FormData();                   
				request.append('img',blobFile);
				$.ajax({
				    type: 'POST',
				    url : 'http://localhost/admin/tariff/upload',
				    data: request,
				    success: function(data){
				    	console.log('success');
				    },
				    error:function(data){
				    	console.log('error');
				    }
				});
			}
		</script>
	</body>
</html>